Skip to content

Conversation

fsammoura1980
Copy link
Contributor

@fsammoura1980 fsammoura1980 commented Oct 6, 2025

The arrays used for M-mode Physical Memory Protection (PMP), specifically for the stack guard feature (CONFIG_PMP_STACK_GUARD), were previously sized using the hardcoded PMP_M_MODE_SLOTS macro, defined as 8. This affected arrays in both the _thread_arch struct (m_mode_pmpaddr_regs, m_mode_pmpcfg_regs) and local variables within the z_riscv_pmp_stackguard_disable function.

This commit changes the array sizing to use the Kconfig option CONFIG_PMP_SLOTS. This option reflects the total number of PMP slots available and configured for the target hardware.

Using CONFIG_PMP_SLOTS ensures these arrays are dimensioned according to the system's actual capabilities, providing better flexibility and correctness over a fixed size.

The PMP_M_MODE_SLOTS macro definition has been removed from thread.h as it is no longer used.

dcpleung
dcpleung previously approved these changes Oct 6, 2025
};
typedef struct z_riscv_fp_context z_riscv_fp_context_t;

#define PMP_M_MODE_SLOTS 8 /* 8 is plenty enough for m-mode */
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldnt we change this to also be set by the kconfig?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I replaced all 4 instances of the deprecated PMP_M_MODE_SLOTS with CONFIG_PMP_SLOTS. The unused PMP_M_MODE_SLOTS definition has been removed. All functional tests are passing, but the change is currently failing the [E Reliability Rating on New Code] check. I'm unsure of the specific requirement this check entails and would appreciate guidance on how to resolve the failure.

The arrays used for M-mode Physical Memory Protection (PMP),
specifically for the stack guard feature (CONFIG_PMP_STACK_GUARD),
were previously sized using the hardcoded PMP_M_MODE_SLOTS macro,
defined as 8. This affected arrays in both the _thread_arch
struct (m_mode_pmpaddr_regs, m_mode_pmpcfg_regs) and local
variables within the z_riscv_pmp_stackguard_disable function.

This commit changes the array sizing to use the Kconfig option
CONFIG_PMP_SLOTS. This option reflects the total number of PMP
slots available and configured for the target hardware.

Using CONFIG_PMP_SLOTS ensures these arrays are dimensioned
according to the system's actual capabilities, providing better
flexibility and correctness over a fixed size.

The PMP_M_MODE_SLOTS macro definition has been removed from
thread.h as it is no longer used.

Signed-off-by: Firas Sammoura <[email protected]>
Copy link

sonarqubecloud bot commented Oct 7, 2025

Quality Gate Failed Quality Gate failed

Failed conditions
E Reliability Rating on New Code (required ≥ C)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Architectures area: RISCV RISCV Architecture (32-bit & 64-bit)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants